package com.comp6521.project01;

import java.io.File;
import java.util.Vector;

public class Main {

	public static void main(String[] args) {

		if (args.length < 2)
		{
			System.out.println("invalid arguments");
			return;
		}

		
		long startTime = System.currentTimeMillis();
		
		String srcFile = args[0]; // get the source file
		String destDir = args[1]; // get the dest dir
		
		// generate sorted lists
		SortedListsGenerator slGenerator = new SortedListsGenerator(srcFile, destDir);
		Vector<String> sortedListFiles = slGenerator.generateSortedLists();
		
		/*
		// delete src file
		File file = new File(srcFile);
		if(!file.delete()){
			System.out.println("Source file Delete operation failed."); 
		}
		*/
		 
		// merge sorted lists
		Merger merger = new Merger(sortedListFiles, destDir);
		merger.merge();
		
		// delete temp files
		for(int i=0; i < sortedListFiles.size(); ++i)
		{
			File file = new File(sortedListFiles.get(i));
			if(!file.delete()){
				System.out.println("temp file delete operation failed."); 
			}
		}
			
		long finishTime = System.currentTimeMillis();
		double totalTime = (double)(finishTime - startTime) / 1000; //in sec
		System.out.println("total time: " + totalTime + " seconds");
		
	}

}
